<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\common\library\Ollama;

/**
 * 机器人管理
 *
 * @icon fa fa-circle-o
 */
class Robot extends Backend
{

    /**
     * Robot模型对象
     * @var \app\common\model\Robot
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\Robot;
    }


    public function getModelByType()
    {
        $res = [];
        if ($type = $this->request->post('custom.type')) {
            switch ($type) {
                case 1://ollama
                    $list = Ollama::list();
                    foreach ($list as $item) {
                        $res[] = [
                            'name' => $item['name'],
                            'model' => $item['model'],
                        ];
                    }
                    break;
                case 2://aiskt
                    $res = [
                        ['name' => 'dall-e-2', 'model' => 'dall-e-2'],
                        ['name' => 'dall-e-3', 'model' => 'dall-e-3'],
                        ['name' => 'gpt-3.5-turbo', 'model' => 'gpt-3.5-turbo'],
                        ['name' => 'gpt-3.5-turbo-0125', 'model' => 'gpt-3.5-turbo-0125'],
                        ['name' => 'gpt-3.5-turbo-0301', 'model' => 'gpt-3.5-turbo-0301'],
                        ['name' => 'gpt-3.5-turbo-0613', 'model' => 'gpt-3.5-turbo-0613'],
                        ['name' => 'gpt-3.5-turbo-1106', 'model' => 'gpt-3.5-turbo-1106'],
                        ['name' => 'gpt-3.5-turbo-16k', 'model' => 'gpt-3.5-turbo-16k'],
                        ['name' => 'gpt-3.5-turbo-16k-0613', 'model' => 'gpt-3.5-turbo-16k-0613'],
                        ['name' => 'gpt-3.5-turbo-instruct', 'model' => 'gpt-3.5-turbo-instruct'],
                        ['name' => 'gpt-4', 'model' => 'gpt-4'],
                        ['name' => 'gpt-4-0125-preview', 'model' => 'gpt-4-0125-preview'],
                        ['name' => 'gpt-4-0314', 'model' => 'gpt-4-0314'],
                        ['name' => 'gpt-4-0613', 'model' => 'gpt-4-0613'],
                        ['name' => 'gpt-4-1106-preview', 'model' => 'gpt-4-1106-preview'],
                        ['name' => 'gpt-4-32k', 'model' => 'gpt-4-32k'],
                        ['name' => 'gpt-4-32k-0314', 'model' => 'gpt-4-32k-0314'],
                        ['name' => 'gpt-4-32k-0613', 'model' => 'gpt-4-32k-0613'],
                        ['name' => 'gpt-4-turbo', 'model' => 'gpt-4-turbo'],
                        ['name' => 'gpt-4-turbo-preview', 'model' => 'gpt-4-turbo-preview'],
                        ['name' => 'gpt-4-turbo-2024-04-09', 'model' => 'gpt-4-turbo-2024-04-09'],
                        ['name' => 'gpt-4-vision-preview', 'model' => 'gpt-4-vision-preview'],
                        ['name' => 'gpt-4o', 'model' => 'gpt-4o'],
                        ['name' => 'gpt-4o-2024-05-13', 'model' => 'gpt-4o-2024-05-13'],
                        ['name' => 'gpt-4o-2024-08-06', 'model' => 'gpt-4o-2024-08-06'],
                        ['name' => 'grok-beta', 'model' => 'grok-beta'],
                    ];
                    break;
                case 3://数字先锋sd
                    $res = [
                        ['name' => 'stable-diffusion', 'model' => 'stable-diffusion'],
                    ];
                    break;
            }
        }
        if ($keyValue = $this->request->post('keyValue')) {
            $selected = [];
            foreach ($res as $item) {
                if ($item['name'] == $keyValue) {
                    $selected = [
                        'name' => $item['name'],
                        'model' => $item['model'],
                    ];
                }
            }
            $res = $selected;
        }
        return json(array(
            'total' => count($res),
            'list' => $res,
        ));
    }

}
